<?php 
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$cate = pdo_getall('snx_coursecate',array('uniacid'=>$_W['uniacid']));
$type=empty($_GPC['type']) ? 'all' :$_GPC['type'];
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$status=$_GPC['status'];
load()->func('tpl');
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where=' WHERE a.uniacid=:uniacid  ';
$data[':uniacid']=$_W['uniacid'];
if(isset($_GPC['keywords'])){
    $where.="  and (a.name LIKE  concat('%', :name,'%') or c.cate_name LIKE  concat('%', :name,'%') or b.course_name LIKE  concat('%', :name,'%'))";
    $data[':name']=$_GPC['keywords']; 
    // $type='all';  
}
 if($type =='cate'){
    $where.="and a.c_id=".$_GPC['id'];
}

$sql="SELECT a.*,b.course_name,c.cate_name FROM ".tablename('snx_course'). " a left join " . tablename("snx_coursecate") . " b on a.c_id=b.id left join" .tablename('snx_school') ."c on b.school_id=c.id" .$where." ORDER BY a.sort asc";

$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('snx_course'). " a"  . " left join " . tablename("snx_coursecate") . " b on a.c_id=b.id left join" .tablename('snx_school') ."c on b.school_id=c.id" .$where." ORDER BY a.sort asc",$data);
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$list=pdo_fetchall($select_sql,$data);
$pager = pagination($total, $pageindex, $pagesize);
// print_r(json_encode($list,320));die;
if($operation=='delete'){
  $roe = pdo_getall("snx_class",array('cou_id'=>$_GPC['id']),array('id'));
  if (!empty($roe)) {
          message('该课程下有分类暂时无法删除','','error');
  }else{
  $res=pdo_delete('snx_course',array('id'=>$_GPC['id']));
  if($res){
    message('删除成功',$this->createWebUrl('subject',array()),'success');
  }else{
    message('删除失败','','error');
  }
}
}
if($_GPC['op']=='change'){
   $res=pdo_update('snx_course',array('status'=>$_GPC['status']),array('id'=>$_GPC['id']));
    if($res){
        message('操作成功',$this->createWebUrl('subject',array()),'success');
    }else{
        message('操作失败','','error');
    }
}
include $this->template('web/subject');

 ?>